/*
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2022-03-22 12:12:49
 * @LastEditTime: 2022-06-29 15:32:33
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description: 多语言控制
 * @FilePath: \vue3-element-plus-web\src\language\handleLanguage.js
 * @Copyright 版权声明
 */
import Cookies from 'js-cookie'
import { SYSTEM_DEFAULT_LANGUAGE, CACHE_MODE } from '@/config'

const Key = 'system-language'

export function getLanguageType() {
  switch (CACHE_MODE) {
    case 'SESSION_STORAGE':
      return sessionStorage.getItem(Key) || SYSTEM_DEFAULT_LANGUAGE
    default:
      return Cookies.get(Key) || SYSTEM_DEFAULT_LANGUAGE
  }
}

export function setLanguageType(lang) {
  switch (CACHE_MODE) {
    case 'SESSION_STORAGE':
      return sessionStorage.setItem(Key, lang)
    default:
      return Cookies.set(Key, lang)
  }
}

export function removeLanguageType() {
  switch (CACHE_MODE) {
    case 'SESSION_STORAGE':
      return sessionStorage.removeItem(Key)
    default:
      return Cookies.remove(Key)
  }
}
